package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/category")
@Api(tags = "分类管理")
@Slf4j
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @ApiOperation("新增分类")
    @PostMapping
    public Result saveCategory(@RequestBody CategoryDTO categoryDTO){
        log.info("参数{}",categoryDTO);
        categoryService.saveCategory(categoryDTO);
        return Result.success();
    }
    @ApiOperation("分类分页查询")
    @GetMapping("/page")
    public Result selectCategory(CategoryPageQueryDTO categoryPageQueryDTO){
        PageResult page = categoryService.seleteCategory(categoryPageQueryDTO);
        return Result.success(page);
    }
    @ApiOperation("修改状态")
    @PostMapping("/status/{status}")
    public Result setStatus(@PathVariable Integer status,Long id){
        categoryService.setStatus(status,id);
        return Result.success();
    }
    @ApiOperation("根据id删除")
    @DeleteMapping
    public Result deleteCategoryById(Integer id){
        categoryService.deleteById(id);
        return Result.success();
    }
    @ApiOperation("修改分类")
    @PutMapping
    public Result updateCategory(@RequestBody CategoryDTO categoryDTO){
        categoryService.updateCatgory(categoryDTO);
        return Result.success();
    }
    @ApiOperation("根据类型查询分类")
    @GetMapping("/list")
    public Result selectByType(Integer type){
        List<Category> list1 = categoryService.selectByType(type);
        return Result.success(list1);
    }


}
